package com.uroad.liaoningpos.dialog;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.uroad.liaoningpos.R;

/**
 * @创建者 wlw
 * @创建时间 2019/5/25 14:41
 * @描述
 */
public class UpdateVersionDialog extends Dialog {
    private Context context;
    private TextView tv_content;
    private TextView tv_cancel;
    private View view_line;
    private TextView tv_ok;
    private OkClickListener okClickListener;
    private TextView tv_title;

    public UpdateVersionDialog(@NonNull Context context) {
        super(context, R.style.motorway_dialog);
        this.context = context;
        initView();
    }

    private void initView() {
        View view = View.inflate(context, R.layout.dialog_update_version, null);

        setContentView(view);
        setCanceledOnTouchOutside(false);
        setCancelable(false);
        tv_title = (TextView) view.findViewById(R.id.tv_title);
        tv_content = (TextView) view.findViewById(R.id.tv_content);
        tv_cancel = (TextView) view.findViewById(R.id.tv_cancel);
        view_line = view.findViewById(R.id.view_line);
        tv_ok = (TextView) view.findViewById(R.id.tv_ok);
        tv_title.setText("发现新版本，开始更新");
        tv_cancel.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (okClickListener != null) {
                    okClickListener.cancelClick();
                }
            }
        });
        tv_ok.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (okClickListener != null) {
                    okClickListener.okClick();
                }
            }
        });
    }

    public void setTitle(String title) {
        if (tv_title != null && !TextUtils.isEmpty(title)) {
            tv_title.setText(title);
        }
    }
    public void setContent(String content) {
        if (tv_content != null && !TextUtils.isEmpty(content)) {
            tv_content.setText(content);
        }
    }

    public void hideCancelbtn(boolean isHideCancelBtn){
        if (isHideCancelBtn) {
            tv_cancel.setVisibility(View.GONE);
            view_line.setVisibility(View.GONE);
        }else{
            tv_cancel.setVisibility(View.VISIBLE);
            view_line.setVisibility(View.VISIBLE);
        }
    }

    public void setOkBtnEnable(boolean isEnable) {
        if (tv_ok != null) {
            tv_ok.setEnabled(isEnable);
        }
    }

    public void setBtnText(String okText, String cancelText) {
        if (tv_ok != null && tv_cancel != null) {
            if (!TextUtils.isEmpty(okText)) {
                tv_ok.setText(okText);
            }
            if (!TextUtils.isEmpty(cancelText)) {
                tv_cancel.setText(cancelText);
            }
        }
    }

    public void setOkClickListener(OkClickListener okClickListener) {
        this.okClickListener = okClickListener;
    }

    public interface OkClickListener{
        void okClick();
        void cancelClick();
    }
}
